﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using EZCRS.HCMS.Data;

namespace EZCRS.HCMS.SqlClient
{
    public class sql_AdminAddress
    {
        private string SqlStr = "";
        #region 常客联系方式信息列表
        public DataTable Address_List(string Uid)
        {
            if (Uid == "")
                return ExecSql.GetDataSet("select * from hfg_user_address order by usetime desc ").Tables[0];
            else
                return ExecSql.GetDataSet("select * from hfg_user_address where uid=" + Uid + " order by usetime desc ").Tables[0];
        }
        #endregion

        #region 常客联系方式信息添加、修改
        /// <summary>
        /// 修改或添加常客联系方式信息
        /// </summary>
        /// <returns></returns>
        public bool Address_Add(string Uid, string Adrtopics, string Usrcountry, string Usrprovince, string Usrcity, string Adrcomment, string Adrpost, string Adrtel, string Adrfax, string Adrcontact, string Indate, string Usetime, string Adrid)
        {
            SqlParameter[] pam = new SqlParameter[12];
            pam[0] = new SqlParameter("@uid", Uid);
            pam[1] = new SqlParameter("@adrtopics", Adrtopics);
            pam[2] = new SqlParameter("@usrcountry", Usrcountry);
            pam[3] = new SqlParameter("@usrprovince", Usrprovince);
            pam[4] = new SqlParameter("@usrcity", Usrcity);
            pam[5] = new SqlParameter("@adrcomment", Adrcomment);
            pam[6] = new SqlParameter("@adrpost", Adrpost);
            pam[7] = new SqlParameter("@adrtel", Adrtel);
            pam[8] = new SqlParameter("@adrfax", Adrfax);
            pam[9] = new SqlParameter("@adrcontact", Adrcontact);
            pam[10] = new SqlParameter("@indate", Indate);
            pam[11] = new SqlParameter("@usetime", Usetime);


            if (Adrid != "")
                SqlStr = "update hfg_user_address set uid=@uid,adrtopics=@adrtopics,usrcountry=@usrcountry,usrprovince=@usrprovince,usrcity=@usrcity,adrcomment=@adrcomment,adrpost=@adrpost,adrtel=@adrtel,adrfax=@adrfax,adrcontact=@adrcontact,indate=@indate,usetime=@usetime where adrid=" + Adrid + "";
            else
                SqlStr = "insert into hfg_user_address(uid,adrtopics,usrcountry,usrprovince,usrcity,adrcomment,adrpost,adrtel,adrfax,adrcontact,indate,usetime) values(@uid,@adrtopics,@usrcountry,@usrprovince,@usrcity,@adrcomment,@adrpost,@adrtel,@adrfax,@adrcontact,@indate,@usetime)";
            if (ExecSql.SqlExecNoquery(SqlStr, pam) > 0)
                return true;
            else
                return false;
        }
        #endregion

        #region 常客联系方式Info数据的显示,显示一条数据
        public DataRow Address_Item(string Adrid)
        {
            try
            {
                return ExecSql.GetDataSet("select * from hfg_user_address where adrid=" + Adrid).Tables[0].Rows[0];
            }
            catch
            {
                return null;
            }

        }
        #endregion

        #region 常客联系方式的删除
        public bool Address_Del(string Adrid)
        {
            string sql = "", msg = "";
            sql = "delete from hfg_user_address where adrid=" + Adrid + "";
            if (ExecSql.SqlExecNoquery(sql) > 0)
                return true;
            else
                return false;
        }
        #endregion
    }
}
